import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_module/other.dart';
class Top extends StatefulWidget {



  @override
  _TopState createState() => _TopState();
}

class _TopState extends State<Top> {

  static const platform = const MethodChannel('my_engine_id');
  String _batteryLevel = 'Unknown battery level.';



  Future<void> _getBatteryLevel() async {
    String batteryLevel;
    try {
      final int result = await platform.invokeMethod('getBatteryLevel');
      batteryLevel = 'Battery level at $result % .';
    } on PlatformException catch (e) {
      batteryLevel = "Failed to get battery level: '${e.message}'.";
    }

    setState(() {
      _batteryLevel = batteryLevel;
    });
  }

  @override
  void initState() {
  MethodChannel("my_engine_id").setMethodCallHandler((call) {

  } );
    super.initState();
  }

  //向native发送消息
  void _sendToNative() {
   
  }
  @override
  Widget build(BuildContext context) {

    return Material(
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            RaisedButton(
              child: Text('Get Battery Level'),
              onPressed: (){
                _getBatteryLevel();
              },
            ),
            Text(_batteryLevel),
          ],
        ),
      ),
    );

  }

}

